/*
This file is part of buco.  
Copyright (c) 2012 Christopher Pawelzik <christopher@cpawelzik.com>

Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php 
*/ 

function SemanticMessagesView(messages) { 
	this.messages = messages; 	
}

SemanticMessagesView.prototype.show = function(target) { 	
	// <span><a href="#">[Bundle1]</a> Bla bla bla</span
	$(target).empty(); 	
	if(this.messages.length == 0) { 
		var span = $("<span>Integrity check done. No problems found.</span>").css("color", "green");			
		$(target).append(span);
	}
	for(var i=0; i < this.messages.length; i++) { 
		var bundleID = this.messages[i].bundleID; 
		var message = this.messages[i].message;
		var type = this.messages[i].type;
		var bundleName = buco.helper.getBundle(bundleID).bundleSymbolicName; 
		var clazz = "message-" + type.toLowerCase();
		var anchor = $("<a></a>").text("[" + bundleName + "]").attr("href", "#").addClass(clazz);  
		// Register click event handler to show the bundle
		var fn = function(bundleID, anchor) {
			$(anchor).click(function() {
				buco.mvc.executeAction("composition.selectBundle", bundleID);
			}); 
		}(bundleID, anchor); 
		
		var span = $("<span></span>");	
		$(span).text(" " + message);
		$(span).prepend(anchor);
		
		$(target).append(span);
		$(target).append("<br />");
	}
}	
